import {
	defineStore
} from 'pinia'

import {
	rsaDecrypt
} from '@/utils/rsa'
import {
	getPersonInfo
} from '@/service/modules/personal'

export const usePersonalStore = defineStore('personal', {
	state: () => ({
		personalInfo: {},
		myIntegral: 0,
		vip: uni.getStorageSync('vip') || false
	}),
	actions: {
		async getPersonInfoAction() {
			const res = await getPersonInfo()
			// 对信息进行解密
			const detail = rsaDecrypt(res.data)
			this.personalInfo = detail
		},

		async getMyIntegralAction() {
			const {
				userName
			} = uni.getStorageSync('userInfo')
			uni.request({
				url: 'http://localhost:3000/integral?userName=' + userName,
				method: "GET",
				success: (res) => {
					this.myIntegral = res.data.data.integral
					console.log('获取积分', res);
				}
			})
		}
	}
})